//
//  SelectView.m
//  ForestPack
//
//  Created by 骆锴 on 2018/8/7.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "SelectView.h"
#import "SelectParameterViewCell.h"
#import "AddImgButton.h"
#import "PaperBoxDetialModel.h"

@interface SelectView()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>

@property (nonatomic, assign) NSInteger         selectType;
@property (nonatomic, strong) UIImageView       *headView;
@property (nonatomic, strong) UILabel           *good_name;
@property (nonatomic, strong) UIButton          *specialDesign;
@property (nonatomic, strong) UIButton          *commonDesign;
@property (nonatomic, strong) BaseTableView     *tableView;
@property (nonatomic, strong) UIButton          *designerButton;
@property (nonatomic, strong) UIButton          *systemButton;
@property (nonatomic, strong) UIView            *baseView;
@property (nonatomic, strong) UIImageView       *commonDesignImage;
@property (nonatomic, strong) NSMutableString   *tempNum;

@end


@implementation SelectView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _isSystemRecord = YES;
        
        self.shadowBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        self.shadowBtn.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
        self.shadowBtn.alpha = 0;
        [self.shadowBtn addTarget:self action:@selector(hidden) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.shadowBtn];
        
        UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - ScreenX375(441), SCREEN_WIDTH, ScreenX375(441))];
        baseView.backgroundColor = [UIColor whiteColor];
        [self addSubview:baseView];
        
        _headView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(-20.5), ScreenX375(100), ScreenX375(100))];
        _headView.image = [UIImage imageNamed:@"头部背景"];
        _headView.clipsToBounds = YES;
        _headView.layer.cornerRadius = 5.0;
        _headView.layer.borderWidth = 0.5;
        _headView.layer.borderColor = [UIColor whiteColor].CGColor;
        [baseView addSubview: _headView];
        
        _good_name = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(123), ScreenX375(13.5), ScreenX375(180), ScreenX375(18))];
        _good_name.text = @"潜水泵常用纸箱";
        _good_name.font = Kfont(18);
        _good_name.textColor = REXADECIMALCOLOR(@"#333333");
        _good_name.textAlignment = NSTextAlignmentLeft;
        [baseView addSubview:_good_name];
        
        _price = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(123), ScreenX375(41), ScreenX375(180), ScreenX375(14))];
        _price.text = @"￥15-45";
        _price.font = Kfont(18);
        _price.textColor = ThemeColor;
        _price.textAlignment = NSTextAlignmentLeft;
        [baseView addSubview:_price];
        
        UIButton *close = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(346), ScreenX375(13), ScreenX375(16), ScreenX375(16))];
        [close setBackgroundImage:[UIImage imageNamed:@"×"] forState:UIControlStateNormal];
        [close addTarget:self action:@selector(hidden) forControlEvents:UIControlEventTouchUpInside];
        [baseView addSubview:close];
        
        UILabel *banmian = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(117), ScreenX375(80), ScreenX375(14))];
        banmian.text = @"版面设计：";
        banmian.font = Kfont(14);
        banmian.textColor = REXADECIMALCOLOR(@"#333333");
        banmian.textAlignment = NSTextAlignmentLeft;
        [baseView addSubview:banmian];
        
        _specialDesign =[[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(86.5), ScreenX375(109.5), ScreenX375(109), ScreenX375(30))];
        [_specialDesign setTitle:@"定制设计" forState:UIControlStateNormal];
        [_specialDesign setTitleColor:REXADECIMALCOLOR(@"#999999") forState:UIControlStateNormal];
        [_specialDesign setTitleColor:ThemeColor forState:UIControlStateSelected];
        [_specialDesign addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
        _specialDesign.titleLabel.font = Kfont(14);
        _specialDesign.layer.cornerRadius = 15.0;
        _specialDesign.layer.borderWidth = 0.5;
        _specialDesign.selected = NO;
        _specialDesign.layer.borderColor = REXADECIMALCOLOR(@"#dcdcdc").CGColor;
        [baseView addSubview:_specialDesign];
        
        _commonDesign =[[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(205.5), ScreenX375(109.5), ScreenX375(109), ScreenX375(30))];
        [_commonDesign setTitle:@"通用设计" forState:UIControlStateNormal];
        [_commonDesign setTitleColor:REXADECIMALCOLOR(@"#999999") forState:UIControlStateNormal];
        [_commonDesign setTitleColor:ThemeColor forState:UIControlStateSelected];
        [_commonDesign addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
        _commonDesign.titleLabel.font = Kfont(14);
        _commonDesign.layer.cornerRadius = 15.0;
        _commonDesign.layer.borderWidth = 0.5;
        _commonDesign.selected = NO;
        _commonDesign.layer.borderColor = REXADECIMALCOLOR(@"#dcdcdc").CGColor;
        [baseView addSubview:_commonDesign];
        
        UIButton *sureBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(367), SCREEN_WIDTH - ScreenX375(26), ScreenX375(44))];
        sureBtn.backgroundColor = ThemeColor;
        sureBtn.layer.cornerRadius = ScreenX375(22);
        sureBtn.clipsToBounds = YES;
        [sureBtn setTitle:@"确 定" forState:UIControlStateNormal];
        [sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        sureBtn.titleLabel.font = Kfont(16);
        [sureBtn addTarget:self action:@selector(done) forControlEvents:UIControlEventTouchUpInside];
        [baseView addSubview:sureBtn];
        
        self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0,ScreenX375(150), SCREEN_WIDTH, ScreenX375(212))];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.backgroundColor = [UIColor whiteColor];
        [baseView addSubview:self.tableView];
    }
    return self;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (_isSelected && _isSpecial && !_isCommon) {
        return 3;
    }else if (_isSelected && !_isSpecial && _isCommon){
        return 2;
    }else{
        return 1;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_isSelected && _isSpecial && !_isCommon) {
        if (indexPath.row < 2) {
            return ScreenX375(44);
        }else{
            return ScreenX375(50);
        }
    }else if (_isSelected && !_isSpecial && _isCommon){
        if (indexPath.row == 0) {
            return ScreenX375(140);
        }else{
            return ScreenX375(50);
        }
    }else{
        return ScreenX375(50);
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_isSelected && _isSpecial && !_isCommon) {
        if (indexPath.row == 0) {
            static NSString *cellId = @"selectsDesignerCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                
                self.designerButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(160), ScreenX375(14))];
                self.designerButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
                [self.designerButton setTitle:@"  选择设计师" forState:UIControlStateNormal];
                [self.designerButton setTitleColor:REXADECIMALCOLOR(@"#333333") forState:UIControlStateNormal];
                self.designerButton.titleLabel.font = Kfont(12);
                [self.designerButton setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
                [self.designerButton setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
                self.designerButton.selected = NO;
                [self.designerButton addTarget:self action:@selector(select:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:self.designerButton];
                
                UIButton *more =[[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(355), ScreenX375(15), ScreenX375(7), ScreenX375(12))];
                [more setBackgroundImage:[UIImage imageNamed:@"更多"] forState:UIControlStateNormal];
                [cell addSubview:more];
                
                _designName =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(200), ScreenX375(15), ScreenX375(140), ScreenX375(14))];
                _designName.font = Kfont(14);
                _designName.textColor = REXADECIMALCOLOR(@"#666666");
                _designName.textAlignment = NSTextAlignmentRight;
                [cell addSubview:_designName];
                
                UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(43), SCREEN_WIDTH - ScreenX375(26), ScreenX375(1))];
                line.image = [UIImage imageNamed:@"虚线"];
                [cell addSubview:line];
                
            }
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else if (indexPath.row == 1){
            static NSString *cellId = @"SystemCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                
                self.systemButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(160), ScreenX375(14))];
                self.systemButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
                [self.systemButton setTitle:@"  系统推荐" forState:UIControlStateNormal];
                [self.systemButton setTitleColor:REXADECIMALCOLOR(@"#333333") forState:UIControlStateNormal];
                self.systemButton.titleLabel.font = Kfont(12);
                [self.systemButton setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
                [self.systemButton setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
                self.systemButton.selected = YES;
                [self.systemButton addTarget:self action:@selector(select:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:self.systemButton];
                
                UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(0), ScreenX375(43), SCREEN_WIDTH, ScreenX375(0.5))];
                line.backgroundColor = REXADECIMALCOLOR(@"#dcdcdc");
                [cell addSubview:line];
            }
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else{
            SelectParameterViewCell *cell = [SelectParameterViewCell cellWithTableView:tableView andIndexPath:indexPath];
            [cell setTitletext:@"数    量："];
            
            if (_baseView == nil) {
                _baseView =[[UIView alloc] initWithFrame:CGRectMake(ScreenX375(87), ScreenX375(7), ScreenX375(109), ScreenX375(30))];
                _baseView.layer.cornerRadius = 15.0;
                _baseView.layer.borderWidth = 0.6;
                _baseView.layer.borderColor = ThemeColor.CGColor;
                _baseView.clipsToBounds = YES;
                
                UIToolbar *bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,ScreenX375(44))];
                UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
                UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
                UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(resignKey)];
                NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
                [bar setItems:buttonsArray];
                
                _num =[[UITextField alloc] initWithFrame:CGRectMake(ScreenX375(35), ScreenX375(0), ScreenX375(39), ScreenX375(30))];
                _num.text = _startAmount;
                _num.tag = 100;
                _num.delegate = self;
                _num.font = Kfont(13);
                _num.layer.borderColor = ThemeColor.CGColor;
                _num.layer.borderWidth = 0.6;
                _num.textColor = REXADECIMALCOLOR(@"#333333");
                _num.textAlignment = NSTextAlignmentCenter;
                _num.inputAccessoryView = bar;
                [_baseView addSubview:_num];
                
                UIButton *leftbutton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(0), ScreenX375(0), ScreenX375(35), ScreenX375(30))];
                leftbutton.tag = 101;
                [leftbutton addTarget:self action:@selector(btnDidClick:) forControlEvents:1];
                [leftbutton setImage:[UIImage imageNamed:@"_"] forState:UIControlStateNormal];
                [leftbutton setTitleColor:ThemeColor forState:UIControlStateNormal];
                [_baseView addSubview:leftbutton];
                
                UIButton *rightbutton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(74), ScreenX375(0), ScreenX375(35), ScreenX375(30))];
                rightbutton.tag = 102;
                [rightbutton addTarget:self action:@selector(btnDidClick:) forControlEvents:1];
                [rightbutton setImage:[UIImage imageNamed:@"+"] forState:UIControlStateNormal];
                [rightbutton setTitleColor:ThemeColor forState:UIControlStateNormal];
                [_baseView addSubview:rightbutton];
                
                [cell addSubview:_baseView];
            }
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
    }else if (_isSelected && !_isSpecial && _commonDesign){
        if (indexPath.row == 0) {
            static NSString *cellId = @"CommomDesginCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                UILabel *commonDesign = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(0), ScreenX375(80), ScreenX375(14))];
                commonDesign.text = @"通用设计：";
                commonDesign.font = Kfont(14);
                commonDesign.textColor = REXADECIMALCOLOR(@"#333333");
                commonDesign.textAlignment = NSTextAlignmentLeft;
                [cell addSubview:commonDesign];
                
                _commonDesignImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(86.5), ScreenX375(0), ScreenX375(79), ScreenX375(79))];
                _commonDesignImage.image = [UIImage imageNamed:@"头部背景"];
                _commonDesignImage.clipsToBounds = YES;
                _commonDesignImage.layer.cornerRadius = 5.0;
                _commonDesignImage.layer.borderWidth = 0.5;
                _commonDesignImage.layer.borderColor = [UIColor whiteColor].CGColor;
                [cell addSubview: _commonDesignImage];
                
                UILabel *logo = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(186), ScreenX375(0), ScreenX375(80), ScreenX375(14))];
                logo.text = @"公司logo：";
                logo.font = Kfont(14);
                logo.textColor = REXADECIMALCOLOR(@"#333333");
                logo.textAlignment = NSTextAlignmentLeft;
                [cell addSubview:logo];
                
                UILabel *Remarks = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(94), ScreenX375(80), ScreenX375(14))];
                Remarks.text = @"设计备注：";
                Remarks.font = Kfont(14);
                Remarks.textColor = REXADECIMALCOLOR(@"#333333");
                Remarks.textAlignment = NSTextAlignmentLeft;
                [cell addSubview:Remarks];
                
                AddImgButton *addImage = [[AddImgButton alloc] initWithFrame:CGRectMake(ScreenX375(257), ScreenX375(0), ScreenX375(79), ScreenX375(79))];
                [cell addSubview:addImage];
                
                _remarkValue = [[UITextField alloc] initWithFrame:CGRectMake(ScreenX375(86.5), ScreenX375(94), ScreenX375(200), ScreenX375(14))];
                _remarkValue.placeholder = @"请输入你的额外需求";
                _remarkValue.font = Kfont(14);
                _remarkValue.textAlignment = NSTextAlignmentLeft;
                [cell addSubview:_remarkValue];
                
                UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(0), ScreenX375(123), SCREEN_WIDTH, ScreenX375(1))];
                line.backgroundColor = REXADECIMALCOLOR(@"#dcdcdc");
                [cell addSubview:line];
            }
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else{
            SelectParameterViewCell *cell = [SelectParameterViewCell cellWithTableView:tableView andIndexPath:indexPath];
            [cell setTitletext:@"数    量："];
            
            if (_baseView == nil) {
                _baseView =[[UIView alloc] initWithFrame:CGRectMake(ScreenX375(87), ScreenX375(7), ScreenX375(109), ScreenX375(30))];
                _baseView.layer.cornerRadius = 15.0;
                _baseView.layer.borderWidth = 0.6;
                _baseView.layer.borderColor = ThemeColor.CGColor;
                _baseView.clipsToBounds = YES;
                
                
                _num =[[UITextField alloc] initWithFrame:CGRectMake(ScreenX375(35), ScreenX375(0), ScreenX375(39), ScreenX375(30))];
                _num.text = _startAmount;
                _num.tag = 100;
                _num.delegate = self;
                _num.font = Kfont(13);
                _num.layer.borderColor = ThemeColor.CGColor;
                _num.layer.borderWidth = 0.6;
                _num.textColor = REXADECIMALCOLOR(@"#333333");
                _num.textAlignment = NSTextAlignmentCenter;
                [_baseView addSubview:_num];
                
                UIButton *leftbutton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(0), ScreenX375(0), ScreenX375(35), ScreenX375(30))];
                leftbutton.tag = 101;
                [leftbutton addTarget:self action:@selector(btnDidClick:) forControlEvents:1];
                [leftbutton setImage:[UIImage imageNamed:@"_"] forState:UIControlStateNormal];
                [leftbutton setTitleColor:ThemeColor forState:UIControlStateNormal];
                [_baseView addSubview:leftbutton];
                
                UIButton *rightbutton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(74), ScreenX375(0), ScreenX375(35), ScreenX375(30))];
                rightbutton.tag = 102;
                [rightbutton addTarget:self action:@selector(btnDidClick:) forControlEvents:1];
                [rightbutton setImage:[UIImage imageNamed:@"+"] forState:UIControlStateNormal];
                [rightbutton setTitleColor:ThemeColor forState:UIControlStateNormal];
                [_baseView addSubview:rightbutton];
                
                [cell addSubview:_baseView];
            }
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
    }else{
        
        SelectParameterViewCell *cell = [SelectParameterViewCell cellWithTableView:tableView andIndexPath:indexPath];
        [cell setTitletext:@"数    量："];
        
        if (_baseView == nil) {
            _baseView =[[UIView alloc] initWithFrame:CGRectMake(ScreenX375(87), ScreenX375(7), ScreenX375(109), ScreenX375(30))];
            _baseView.layer.cornerRadius = 15.0;
            _baseView.layer.borderWidth = 0.6;
            _baseView.layer.borderColor = ThemeColor.CGColor;
            _baseView.clipsToBounds = YES;
            
            UIToolbar *bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,ScreenX375(44))];
            UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
            UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
            UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(resignKey)];
            NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
            [bar setItems:buttonsArray];
            
            _num =[[UITextField alloc] initWithFrame:CGRectMake(ScreenX375(35), ScreenX375(0), ScreenX375(39), ScreenX375(30))];
            _num.text = _startAmount;
            _num.tag = 100;
            _num.font = Kfont(13);
            _num.delegate = self;
            _num.layer.borderColor = ThemeColor.CGColor;
            _num.layer.borderWidth = 0.6;
            _num.textColor = REXADECIMALCOLOR(@"#333333");
            _num.textAlignment = NSTextAlignmentCenter;
            _num.inputAccessoryView = bar;
            [_baseView addSubview:_num];
            
            UIButton *leftbutton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(0), ScreenX375(0), ScreenX375(35), ScreenX375(30))];
            leftbutton.tag = 101;
            [leftbutton addTarget:self action:@selector(btnDidClick:) forControlEvents:1];
            [leftbutton setImage:[UIImage imageNamed:@"_"] forState:UIControlStateNormal];
            [leftbutton setTitleColor:ThemeColor forState:UIControlStateNormal];
            [_baseView addSubview:leftbutton];
            
            UIButton *rightbutton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(74), ScreenX375(0), ScreenX375(35), ScreenX375(30))];
            rightbutton.tag = 102;
            [rightbutton addTarget:self action:@selector(btnDidClick:) forControlEvents:1];
            [rightbutton setImage:[UIImage imageNamed:@"+"] forState:UIControlStateNormal];
            [rightbutton setTitleColor:ThemeColor forState:UIControlStateNormal];
            [_baseView addSubview:rightbutton];
            
            [cell addSubview:_baseView];
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}

-(void)btnDidClick:(UIButton*)sender{
    if (sender.tag == 101) {
        NSString *num = [[NSString alloc] init];
        num = _num.text;
        if ([_num.text integerValue] - 1 < [_startAmount integerValue] ) {
            [HttpManager showNoteMsg:@"数量不能少于起订数量"];
            _num.text = num;
        }else{
            _num.text = [[NSString alloc] initWithFormat:@"%ld",[num integerValue] - 1];
        }
    }else{
        NSString *num = [[NSString alloc] init];
        num = _num.text;
        _num.text = [[NSString alloc] initWithFormat:@"%ld",[num integerValue] + 1];
    }
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_isSelected && _isSpecial && !_isCommon){
        if (indexPath.row == 0) {
            if (_turnToSelectDesignerClick) {
                _turnToSelectDesignerClick();
            }
        }
    }
}

- (void)select:(UIButton *)button {
    if (button == _designerButton) {
        _designerButton.selected = YES;
        _systemButton.selected = NO;
        _isSystemRecord = NO;
    }else{
        _designerButton.selected = NO;
        _systemButton.selected = YES;
        _isSystemRecord = YES;
    }
}

-(void)textFieldDidBeginEditing:(UITextField *)textField{
    if (_num == textField) {
         _tempNum = [textField.text mutableCopy];
    }
}

- (void)hidden {
    if (_hiddenClick) {
        _hiddenClick();
    }
}

- (void)done {
    if (_doneClick) {
        _doneClick();
    }
}

-(void)setTurnToSelectDesigner{
    if (_turnToSelectDesignerClick) {
        _turnToSelectDesignerClick();
    }
}

- (void)selectType:(UIButton *)button {
    if (button == _specialDesign) {
        _specialDesign.selected = YES;
        _specialDesign.layer.borderColor = ThemeColor.CGColor;
        _commonDesign.selected = NO;
        _commonDesign.layer.borderColor = REXADECIMALCOLOR(@"#dcdcdc").CGColor;
        _isSelected = YES;
        _isSpecial = YES;
        _isCommon = NO;
        [self.tableView reloadData];
    }else{
        _specialDesign.selected = NO;
        _specialDesign.layer.borderColor = REXADECIMALCOLOR(@"#dcdcdc").CGColor;
        _commonDesign.selected = YES;
        _commonDesign.layer.borderColor = ThemeColor.CGColor;
        _isSelected = YES;
        _isSpecial = NO;
        _isCommon = YES;
        [self.tableView reloadData];
    }
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
    if (_num == textField) {
        if ([textField.text integerValue] < [_startAmount integerValue]) {
            [HttpManager showNoteMsg:@"数量不能少于起订数量"];
            textField.text = _tempNum;
        }
    }
}

-(void)resignKey{
    [_num resignFirstResponder];
}

@end
